<template>
	<view class="news">
		<!--  子向父传值 一种是通过$event 拿到传过来的数据  另一种是不用加括号-->
		<news-list :newsList="newsList" @goNewsDetail="goNews"></news-list>
		<!-- <button type="default" @click="goDetail">跳转</button> -->
	</view>
</template>

<script>
	//  1 导入子组件 2 注册为子组件 3 页面使用并传递数据
	import newList from '../../components/news-item/news-item.vue'
	export default {
		components:{
			"news-list": newList
		},
		data() {
			return {
				// 资讯列表
				newsList:[]
			}
		},
		onLoad() {
			this.getNews()
		},
		methods: {
			async getNews() {
				const res = await this.$http({
					url:'/api/getnewslist'
				})
				this.newsList = res.data.message
				// console.log(this.newsList)
			},
			goNews(id) {
				// console.log(id,11111)
				uni.navigateTo({
					// url:'/pages/newsDetail/newsDetail?id=' + id
					url:'/pages/newsDetail/newsDetail?id=' + id
				})
				
			}
			// goDetail() {
				
			// }
			
		}
	}
</script>

<style lang="scss">

</style>
